package cn.com.greatwall.flowable.config;

import org.flowable.idm.engine.IdmEngineConfiguration;
import org.flowable.idm.spring.SpringIdmEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.com.greatwall.flowable.identity.CustomGroupEntityManager;
import cn.com.greatwall.flowable.identity.CustomUserEntityManager;

/**
 * @Author herw
 * @Time 2020-09-22 12:19:30
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
@Configuration
public class FlowableIdmConfig implements EngineConfigurationConfigurer<SpringIdmEngineConfiguration> {
    @Override
    public void configure(SpringIdmEngineConfiguration engineConfiguration) {
        engineConfiguration.setGroupEntityManager(customGroupEntityManager(engineConfiguration));
        engineConfiguration.setUserEntityManager(customUserEntityManager(engineConfiguration));
    }
    
    @Bean
    public CustomGroupEntityManager customGroupEntityManager(IdmEngineConfiguration configuration) {
        return new CustomGroupEntityManager(configuration, configuration.getGroupDataManager());
    }
    
    @Bean
    public CustomUserEntityManager customUserEntityManager(IdmEngineConfiguration configuration) {
        return new CustomUserEntityManager(configuration, configuration.getUserDataManager());
    }
}
